package jobs

import (
	"fmt"
	"github.com/robfig/cron"
	"mongo/logs"
)

type AutoJobService struct {
	autoDropLanGuo       *AutoDropCollection
	autoDropOpenplatform *AutoDropCollection
	cron                 *cron.Cron
}

func NewService(autoDropLanGuo, autoDropOpenplatform *AutoDropCollection) *AutoJobService {
	service := AutoJobService{autoDropLanGuo: autoDropLanGuo, autoDropOpenplatform: autoDropOpenplatform}
	service.cron = cron.New()
	return &service
}

func (service *AutoJobService) Start() {
	fmt.Println("starting to add the languo job...")
	logs.Logger.Info("starting to add the languo job...")
	service.cron.AddFunc(service.autoDropLanGuo.cron, service.autoDropLanGuo.Run)
	fmt.Println("starting to add the openplatform job...")
	logs.Logger.Info("starting to add the openplatform job...")
	service.cron.AddFunc(service.autoDropOpenplatform.cron, service.autoDropOpenplatform.Run)
	defer service.cron.Stop()
	service.cron.Start()
	select {}
	logs.Logger.Info("jobs were end.")
}
